<?php
namespace backend\models;


use yii\base\Model;
use yii\db\ActiveQuery;

class SearchForm extends Model
{
    public $goods_name;
    public $goods_sn;
    public $goods_status;
    public $gasp;
    public $gisp;



    public function rules()
    {
        return [
            [['goods_name','goods_sn'],'string'],
            [['gasp','gisp'],'double'],
            [['goods_status'],'integer'],
        ];
    }

    public  function search(ActiveQuery &$query)
    {
        $this->load(\Yii::$app->request->get());
         $query->andFilterWhere(['like','name',isset($this->goods_name)?$this->goods_name:null])
            ->andFilterWhere(['like','sn',isset($this->goods_sn)?$this->goods_sn:null])
            ->andFilterWhere(['<','shop_price',isset($this->gasp) && $this->gasp !=0?floatval($this->gasp):null])
            ->andFilterWhere(['>','shop_price',isset($this->gisp) && $this->gisp !=0?floatval($this->gisp):null])
            ->andFilterWhere(['=','status',isset($this->goods_status)?(int)$this->goods_status:1]);
//         var_dump($query);exit;
    }
}